package dao;

import model.Business;
import model.BusinessType;
import model.Food;
import util.Util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class FoodDao {
    public List<Food> findFoodByBusinessId(int id) {
        List<Food> list = new ArrayList<Food>();
        Connection con = null;
        PreparedStatement preparedStatement = null;
        ResultSet rs = null;
        try {
            con = Util.getConnection();
            String sql = "select * from food where businessid=?";
            preparedStatement = con.prepareStatement(sql);
            preparedStatement.setInt(1, id);
            rs = preparedStatement.executeQuery();
            while (rs.next()) {
                Food food = new Food(rs.getInt(1),rs.getString(2),rs.getString(3),rs.getString(4),rs.getFloat(5),0,rs.getInt(6));
                list.add(food);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                Util.closeConnection(con);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return list;
    }

}
